package main

import (
	"fmt"
	"log"
	"os"

	"github.com/urfave/cli/v2"
)

func main() {
	/*
		var language string

		app := &cli.App{
			Name:  "greet",
			Usage: "fight the loneliness!",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:        "lang",
					Aliases:     []string{"l", "language"},
					Value:       "English",
					Usage:       "language for the greeting from `FILE`",
					Destination: &language,
				},
			},
			Action: func(c *cli.Context) error {
				name := "world"
				if c.NArg() > 0 {
					name = c.Args().Get(0)
				}
				if language == "english" {
					fmt.Println("hello", name)
				} else {
					fmt.Println("你好", name)
				}
				return nil
			},
		}

		if err := app.Run(os.Args); err != nil {
			log.Fatal(err)
		}
	*/

	app := &cli.App{
		Commands: []*cli.Command{
			{
				Name:    "add",
				Aliases: []string{"a"},
				Usage:   "add a task to the list",
				Action: func(c *cli.Context) error {
					fmt.Println("added task: ", c.Args().First())
					return nil
				},
			},
			{
				Name:    "complete",
				Aliases: []string{"c"},
				Usage:   "complete a task to the list",
				Action: func(c *cli.Context) error {
					fmt.Println("completed task: ", c.Args().First())
					return nil
				},
			},
			{
				Name:    "template",
				Aliases: []string{"t"},
				Usage:   "options for task templates",
				Subcommands: []*cli.Command{
					{
						Name:  "add",
						Usage: "add a new template",
						Action: func(c *cli.Context) error {
							fmt.Println("new task template: ", c.Args().First())
							return nil
						},
					},
					{
						Name:  "remove",
						Usage: "remove an existing template",
						Action: func(c *cli.Context) error {
							fmt.Println("removed task template: ", c.Args().First())
							return nil
						},
					},
				},
			},
		},
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}

}
